tree grammar Process0Walker1;

options {
  language = Java;
  tokenVocab = Process0;
  ASTLabelType = CommonTree;
}

@header {
  package process0.gen;
    import process0.ast.Workflow;
    import process0.ast.Process;
    import process0.ast.Action;
    import process0.ast.States;
    import process0.ast.Timeline;
}

process returns[Process process]
  : {process = null;}
  ^(
    IDENT {process = new Process($IDENT.text);} 
    (
      t = timeline {process.setTimeline(t);}
    )?
    (
      w = workflow {process.addWorkflow(w);}
    )*  
   )
   {return process;}
  ;

timeline returns [Timeline timeline]
  : {timeline = null;}
    ^(
      'timeline' IDENT{timeline = new Timeline($IDENT.text);}
      (  
        t = timeline {timeline.addTimeline(t);}
      )*
     ) 
    {return timeline;}
  ;
workflow returns [Workflow workflow]
  : {workflow = null;}
    ^(
      'workflow'
      IDENT{workflow = new Workflow($IDENT.text);} 
      (
        a=action {workflow.addAction(a);}
      )+
     )
     {return workflow;}
  ;

action returns [Action action]
  :{action = null;}
    ^(
      IDENT {action = new Action($IDENT.text);}
      (
        s = states { action.addStates(s);}
      )+
     ) {return action;}
  ;
  
states returns [States states]
  :{states = new States();}
    ^(
      e = IDENT {states.setEndState($e.text);} 
      b1=IDENT {states.addInitialState($b1.text);}
      (
        b=IDENT {states.addInitialState($b.text);}
      )* 
     )
     {return states;}
  ;